package org.bemuv;

import java.util.List;
import java.util.Vector;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.parse.Parse; //Libreria del backend
import com.parse.ParseObject;


public class ListAdapter extends BaseAdapter {

	private final Activity activity;
	private final List list;

	public ListAdapter(Activity actividad, List<ParseObject> list) {
		super();
		this.activity = actividad;
		this.list = list;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = activity.getLayoutInflater();
		View view = inflater.inflate(R.layout.list_element, null, true);
		ParseObject obj = (ParseObject)list.get(position);

		TextView txt_name_object = (TextView) view.findViewById(R.id.name_object);
		TextView txt_price_object = (TextView) view.findViewById(R.id.price_object);
		TextView txt_description_object = (TextView) view.findViewById(R.id.description_object);
		
		txt_name_object.setText(obj.getString("nameObject"));	
		txt_price_object.setText(obj.getString("priceObject"));
		txt_description_object.setText(obj.getString("descriptionObject"));
		
		ImageView imageView = (ImageView) view.findViewById(R.id.icono);
		switch (Math.round((float) Math.random() * 3)) {
		case 0:
			//imageView.setImageResource(R.drawable.asteroide1);
			break;
		case 1:
			//imageView.setImageResource(R.drawable.asteroide2);
			break;
		default:
			//imageView.setImageResource(R.drawable.asteroide3);
			break;
		}
		return view;
	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int arg0) {
		//return list.elementAt(arg0);
		return null; //borrar es temporal
	}

	public long getItemId(int position) {
		return position;
	}

}
